home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / 0141ter2.zip / 0141TER2._XE / PASCAL.EXE / LSTPHONE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-07  |  1KB  |  48 lines

  1. Program ListPhoneBook;
  2.  
  3. { A small Terminate utility to show how to use the phonebook }
  4. {       Structures are Copyrighted by Bo Bendtsen 1992       }
  5.  
  6. {$I PHONE.100}
  7.  
  8. Var
  9.   PhoneFile : File;
  10.   x         : Word;
  11.  
  12. Procedure FatalError(s:string);
  13. Begin
  14.   WriteLn('Fatal: '+s+#10#10);
  15.   Halt;
  16. End;
  17.  
  18. Begin
  19.  
  20.   FillChar(PHead,Sizeof(PHead),0);
  21.   Assign(PhoneFile,'TERMINAT.FON');
  22.   {$I-} Reset(PhoneFile,1); {$I+}
  23.   If IOResult=0 Then
  24.   Begin
  25.  
  26.     { Read the header in the phone file }
  27.     {$I-} BlockRead(PhoneFile,PHead,Sizeof(PHead)); {$I+}
  28.     If IOResult<>0 Then FatalError('Error in start of phonebook');
  29.  
  30.     { Read all records into structure }
  31.     For x:=1 to PHead.Num Do
  32.     Begin
  33.       New(Ph[x]); { Reserve memory }
  34.       {$I-} BlockRead(PhoneFile,Ph[x]^.P,Sizeof(Ph[x]^.P)); {$I+}
  35.       If IOResult<>0 Then FatalError('Error in phonebook, maybe wrong version');
  36.     End;
  37.  
  38.     Close(PhoneFile);
  39.   End;
  40.  
  41.   { Write all phonenumbers on screen }
  42.   For x:=1 to PHead.Num Do WriteLn(Ph[x]^.P.Name);
  43.  
  44.   { Free memory before exiting }
  45.   For x:=1 to PHead.Num Do Dispose(Ph[x]);
  46.  
  47. End.
  48.